#include "lm_mem.h"
#include <stdio.h>
#include <stdlib.h>


#define LM_HEAP_POOL_SIZE    1024*1024*50
static void* lm_mem_pool = NULL;
static tlsf_t tlsf_pool;

int lm_mem_init(void)
{
    lm_mem_pool = malloc(LM_HEAP_POOL_SIZE);
    if(lm_mem_pool == NULL) {
        return -1;
    }

    tlsf_pool = tlsf_create_with_pool(lm_mem_pool, LM_HEAP_POOL_SIZE);

    return 0;
}


void* lm_malloc(size_t size)
{
    return tlsf_malloc(lm_mem_pool, size);
}


void lm_free(void *p)
{
    tlsf_free(lm_mem_pool, p);
}


void lm_mem_destroy(void)
{
    tlsf_destroy(tlsf_pool);
    free(lm_mem_pool);
}
